package com.headfirst.ooad;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Inventory {

	private List<Guitar> guitars;

	public List<Guitar> search(GuitarSpec searchSpec) {
		List<Guitar> matchingGuitars = new LinkedList<Guitar>();
		for (Iterator<Guitar> i = guitars.iterator(); i.hasNext();) {
			Guitar guitar = (Guitar) i.next();
			GuitarSpec guitarSpec = guitar.getSpec();
			if (searchSpec.getBuilder() != guitarSpec.getBuilder())
				continue;
			String model = searchSpec.getModel().toLowerCase();
			if ((model != null) && (!model.equals(""))
					&& (!model.equals(guitarSpec.getModel().toLowerCase())))
				continue;
			if (searchSpec.getType() != guitarSpec.getType())
				continue;
			if (searchSpec.getBackWood() != guitarSpec.getBackWood())
				continue;
			if (searchSpec.getTopWood() != guitarSpec.getTopWood())
				continue;
			matchingGuitars.add(guitar);
		}
		return matchingGuitars;
	}
}